package com.matrix.draft.helloworld.apprentice;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String input = "1";
        Scanner sc = new Scanner(System.in);
        Scanner bookSc = new Scanner(System.in);
        List<Book> db = new LinkedList<Book>(){{
            add(new Book("陶雅情B1","陶雅情之书","陶雅情","Java练习两年半",999.999f));
        }};
        do {
            System.out.println("请输入功能: \n1.显示数据\n2.录入数据\n3.退出程序");
            input = sc.nextLine().trim();
            if ("1".equals(input)) {
                System.out.println("--------------------------------------------------------");
                System.out.println("版权\t\t书名\t\t作者\t\t出版社\t\t价格");
                System.out.println("--------------------------------------------------------");
                for (Book book : db) {
                    System.out.println(String.format("%s\t\t%s\t\t%s\t\t%s\t\t%s",
                            book.getVersion(),
                            book.getName(),
                            book.getAuthor(),
                            book.getPress(),
                            book.getPrice()
                    ));
                }
                System.out.println("--------------------------------------------------------\n\n");
            } else if ("2".equals(input)) {
                System.out.print("请输入版权: ");
                String version = bookSc.nextLine();
                System.out.print("请输入书名: ");
                String name = bookSc.nextLine();
                System.out.print("请输入作者: ");
                String author = bookSc.nextLine();
                System.out.print("请输入出版社: ");
                String press = bookSc.nextLine();
                System.out.print("请输入价格: ");
                String price = bookSc.nextLine();
                db.add(new Book(version,name,author,press,Float.parseFloat(price)));
            }
        } while (!"3".equals(input));
    }

}
